package com.trxy.controller.back;

import com.trxy.model.User;
import com.trxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@Controller
@RequestMapping("/back/center")
public class CenterController {

    @Autowired
    UserService userService;

    @RequestMapping("/index")
    String index() {
        return "back/center/index";
    }

    @RequestMapping("/indexWelcome")
    String indexWelcome() {
        return "back/center/index-welcome";
    }

    @RequestMapping("/list")
    String adminList(Model model) {
        List<User> adminList = userService.selectAll("xiaoming");
        model.addAttribute("AdminList", adminList);
        return "back/admin/admin-list";
    }

    @RequestMapping("/state")
    String stateAdmin(int id){
        User user = userService.userState (id);
        if (user.getState ().equals ("禁用")){
            userService.updateState("启用",id);
            return "redirect:/back/center/list";
        }else if (user.getState ().equals ("启用")){
            userService.updateState("禁用", id);
            return "redirect:/back/center/list";
        }else {
            return "redirect:/back/center/list";
        }
    }
}
